package com.miyu.rabbitmq.service;

import com.alibaba.fastjson2.JSONObject;
import com.miyu.rabbitmq.pojo.SysMqConfig;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("mq")
@RequiredArgsConstructor
public class RabbitController {
        /**
         * 服务对象
         */
        private final RabbitService rabbitService;

        /**
         * 新增mq配置
         *
         * @param params 实体
         * @return 新增是否成功
         */
        @ApiOperation(value = "新增mq配置")
        @PostMapping(value = "add")
        public JSONObject add(@RequestBody JSONObject params) {
        SysMqConfig mqConfig = JSONObject.parseObject(params.toString(), SysMqConfig.class);
        return rabbitService.add(mqConfig);
    }

        /**
         * 修改mq配置
         *
         * @param mqConfig 实体
         * @return 修改是否成功
         */
        @ApiOperation(value = "修改mq配置")
        @RequestMapping(value = "update", produces = "application/json;charset=utf-8")
        public JSONObject update(@RequestBody SysMqConfig mqConfig) {
        return rabbitService.update(mqConfig);
    }

        /**
         * 删除mq配置
         *
         * @param mqIds 主键
         * @return 删除是否成功
         */
        @ApiOperation(value = "删除mq配置")
        @DeleteMapping(value = "deleteById", produces = "application/json;charset=utf-8")
        public JSONObject deleteById(String[] mqIds) {

        return rabbitService.delete(mqIds);
    }

        /**
         * @param params
         * @return
         */
        @RequestMapping(value = "sendMessage")
        public JSONObject sendMessage(@RequestBody JSONObject params) {
        return rabbitService.sendMessage(params);
    }

        /**
         * @param params
         */
        @RequestMapping(value = "recieveMessage")
        public void recieveMessage (@RequestBody  JSONObject params) {
            rabbitService.recieveMessage(params);
    }

        /**
         * 查询系统mqconfig
         *
         * @param params
         * @return
         */
        @RequestMapping("querySysMqConfig")
        public List<SysMqConfig> querySysMqConfig(@RequestBody  JSONObject params) {

        return rabbitService.querySysMqConfig(params);
    }

}
